package models

import (
	"github.com/astaxie/beego/orm"
	//_ "github.com/go-sql-driver/mysql"
	_ "gitee.com/haofenfen/mysql"
	"github.com/astaxie/beego"
)

type Page struct {
	Id int
	Website string
	Email string
}


func init()  {
	//maxIdleConn ,err := beego.AppConfig.Int("mysql_max_idle_conn")
	//if err != nil{
	//	beego.Error("Mysql max idle con is invalid: ",err)
	//}
	// 注册驱动
	err := orm.RegisterDriver("mysql", orm.DRMySQL)
	if err != nil {
		beego.Error("Orm register driver is err: ", err)
		return
	}

	// 注册数据库
	orm.RegisterDataBase("default","mysql","root:123456@tcp(39.107.24.71:9021)/gocms?charset=utf8")

	// 注册表模型
	orm.RegisterModel(new(Page))
}

func GetPage() Page  {
	//page := Page{Website:"Go网站标题",Email:"liuzhuang@6iuu.com"}
	//return page

	o := orm.NewOrm()
	p := Page{Id:1}
	err := o.Read(&p)
	if err !=nil{
		beego.Error("read page info error : ",err)
	}
	return p
}

func UpdatePage()  {
	p := Page{Id:1,Website:"网站标题3"}
	o := orm.NewOrm()
	o.Update(&p,"website")
	//if err !=nil{
	//	beego.Error("update Page error ： ",err)
	//}
}